/**
 * Created by root on 17-6-23.
 */
var logger = require('../config/log4js');

module.exports = {

    isEmpty:function () {
        for(var i = 0;i < arguments.length; i++) {
            logger.access.info(arguments[i]);
            if (arguments[i] === undefined || arguments[i] === null || arguments[i] === "" || arguments[i].length === 0)
                return true;
        }
        return false;
    },

    getIPIndexByPosition:function (position) {
        let map = {'河北':'00', '山西':'01', '辽宁':'02', '吉林':'03', '黑龙江':'04', '江苏':'05', '浙江':'06', '安徽':'07', '福建':'08', '江西':'09', '山东':'10', '河南':'11', '湖北':'12', '湖南':'13', '广东':'14', '海南':'15', '四川':'16', '贵州':'17', '云南':'18', '陕西':'19', '甘肃':'20', '青海':'21', '台湾':'22'};

        return map[position];
    },

    getPositionByIP:function (ip) {

    },

    /**
     * 弹窗跳转
     * @param msgText 弹窗内容
     * @param msgUrl 跳转页面*/
    gotoMsg:function (msgText, msgUrl, res) {
        res.render('msg', {msgText : msgText, msgUrl : msgUrl});
    },

    /**
     * 根据request获取客户端ip
     * @param request
     * @return ip
     * */
    getClientIP:function (req) {
        return req.headers['x-forwarded-for'] ||
            req.connection.remoteAddress ||
            req.socket.remoteAddress ||
            req.connection.socket.remoteAddress;
    }

}